package ru.mti.edu.requestdispatching;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RedirectServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		boolean isRedirect = req.getParameter("redirect") != null;
		if (isRedirect){
			resp.sendRedirect(resp.encodeRedirectURL(req.getContextPath() + "/index.html"));
		}
		else {
			RequestDispatcher rd = req.getRequestDispatcher("login.html");
			if (rd != null){
				rd.forward(req, resp);
			}
		}
	}

	
}
